<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>strncmp</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">Standard C String and Character</a> &gt; <a href=
    "strncmp.html">strncmp</a>
  </div>

  <div class="name-format">
    strncmp
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;string.h&gt;
  int strncmp( const char *str1, const char *str2, size_t count );
</pre>

  <p>The strncmp() function compares at most <em>count</em> characters
  of <em>str1</em> and <em>str2</em>. The return value is as
  follows:</p>

  <table class="code-table">
    <tr>
      <th class="code-table-th">Return value</th>

      <th class="code-table-th">Explanation</th>
    </tr>

    <tr>
      <td class="code-table-td">less than 0</td>

      <td class="code-table-td">&#39;&#39;str1&#39;&#39; is less than
      &#39;&#39;str2&#39;&#39;</td>
    </tr>

    <tr>
      <td class="code-table-td">equal to 0</td>

      <td class="code-table-td">&#39;&#39;str1&#39;&#39; is equal to
      &#39;&#39;str2&#39;&#39;</td>
    </tr>

    <tr>
      <td class="code-table-td">greater than 0</td>

      <td class="code-table-td">&#39;&#39;str1&#39;&#39; is greater
      than str2&#39;&#39;</td>
    </tr>
  </table>

  <p>If there are less than <em>count</em> characters in either string,
  then the comparison will stop after the first null termination is
  encountered.</p>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="strchr.html">strchr</a><br>
    <a href="strcmp.html">strcmp</a><br>
    <a href="strcpy.html">strcpy</a><br>
    <a href="strlen.html">strlen</a><br>
    <a href="strncat.html">strncat</a><br>
    <a href="strncpy.html">strncpy</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
